/**
 * Zhz.net Inc.
 * Copyright (c) 2004-2010 All Rights Reserved.
 */
package com.zhz.lib.project.service;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;

import com.zhz.lib.project.domain.news.Sortmap;
import com.zhz.project.common.util.alibaba.ArrayUtil;
import com.zhz.project.common.util.alibaba.StringUtil;
import com.zhz.project.common.util.hibernate.BaseDAO;

/**
 * 
 * @author Administrator
 * @version $Id: FaqService.java, v 0.1 Sep 16, 2010 7:57:37 AM Administrator
 *          Exp $
 */
public class TypeService implements InitializingBean {
    private static Logger       logger                      = Logger.getLogger(TypeService.class);

    @Autowired
    private BaseDAO             baseDao;

    private String              tongzhiyuxiaoxi;
    private String              tongzhiyuxiaoxiIndex;
    private ArrayList<String>   tongzhiyuxiaoxiList         = new ArrayList<String>();
    private ArrayList<Sortmap>  tongzhiyuxiaoxiSortmapList  = new ArrayList<Sortmap>();

    private String              guanneixinxi;
    private String              guanneixinxiIndex;
    private ArrayList<String>   guanneixinxiList            = new ArrayList<String>();
    private ArrayList<Sortmap>  guanneixinxiSortmapList     = new ArrayList<Sortmap>();

    private String              yewujiaoliu;
    private String              yewujiaoliuIndex;
    private ArrayList<String>   yewujiaoliuList             = new ArrayList<String>();
    private ArrayList<Sortmap>  yewujiaoliuSortmapList      = new ArrayList<Sortmap>();

    private String              tushuguanfengcai;
    private String              tushuguanfengcaiIndex;
    private ArrayList<String>   tushuguanfengcaiList        = new ArrayList<String>();
    private ArrayList<Sortmap>  tushuguanfengcaiSortmapList = new ArrayList<Sortmap>();

    private String              xiazaikongjian;
    private String              xiazaikongjianIndex;
    private ArrayList<String>   xiazaikongjianList          = new ArrayList<String>();
    private ArrayList<Sortmap>  xiazaikongjianSortmapList   = new ArrayList<Sortmap>();

    // ////////////////////////////////////////////////
    private String              customlinks;

    private Map<String, String> linksMap                    = new LinkedHashMap<String, String>();

    public void afterPropertiesSet() throws Exception {
        // TODO,捕获异常，不要影响启动！！
        // 通知与消息
        for (String str : tongzhiyuxiaoxiList) {
            try {
                Sortmap sortmap = (Sortmap) baseDao.findOneObject("Sortmap", "sortMapId", str);
                tongzhiyuxiaoxiSortmapList.add(sortmap);
            } catch (Exception e) {
                logger.error("根据id获取通知与信息类型时发生异常,id=" + str, e);
            }
        }
        // 馆内信息
        for (String str : guanneixinxiList) {
            try {
                Sortmap sortmap = (Sortmap) baseDao.findOneObject("Sortmap", "sortMapId", str);
                guanneixinxiSortmapList.add(sortmap);
            } catch (Exception e) {
                logger.error("根据id获取馆内信息类型时发生异常,id=" + str, e);
            }
        }
        // 业务交流
        for (String str : yewujiaoliuList) {
            try {
                Sortmap sortmap = (Sortmap) baseDao.findOneObject("Sortmap", "sortMapId", str);
                yewujiaoliuSortmapList.add(sortmap);
            } catch (Exception e) {
                logger.error("根据id获取业务交流类型时发生异常,id=" + str, e);
            }
        }
        // 图书馆风采
        for (String str : tushuguanfengcaiList) {
            try {
                Sortmap sortmap = (Sortmap) baseDao.findOneObject("Sortmap", "sortMapId", str);
                tushuguanfengcaiSortmapList.add(sortmap);
            } catch (Exception e) {
                logger.error("根据id获取图书馆风采类型时发生异常,id=" + str, e);
            }
        }

        // 下载空间
        for (String str : xiazaikongjianList) {
            try {
                Sortmap sortmap = (Sortmap) baseDao.findOneObject("Sortmap", "sortMapId", str);
                xiazaikongjianSortmapList.add(sortmap);
            } catch (Exception e) {
                logger.error("根据id获取下载空间类型时发生异常,id=" + str, e);
            }
        }
        // ///////////////////////////////////////////////////

        List<String> linksList = new ArrayList<String>();
        linksList.addAll(ArrayUtil.toList(StringUtil.split(customlinks, ",")));

        for (String link : linksList) {
            String[] temp = StringUtil.split(link, ";");
            linksMap.put(temp[0], temp[1]);
        }

    }

    public void setToModelMap(ModelMap model) {

        // 通知与消息
        model.addAttribute("tongzhiyuxiaoxiSortmapList", tongzhiyuxiaoxiSortmapList);

        // 馆内信息
        model.addAttribute("yewujiaoliuSortmapList", yewujiaoliuSortmapList);

        // 业务交流
        model.addAttribute("guanneixinxiSortmapList", guanneixinxiSortmapList);

        // 图书馆风采
        model.addAttribute("tushuguanfengcaiSortmapList", tushuguanfengcaiSortmapList);

        // 下载空间
        model.addAttribute("xiazaikongjianSortmapList", xiazaikongjianSortmapList);

        // ////////////////////////////////
        model.addAttribute("entrySet", linksMap.entrySet());
    }

    public String getGuanneixinxi() {
        return guanneixinxi;
    }

    public String getGuanneixinxiIndex() {
        return guanneixinxiIndex;
    }

    public ArrayList<String> getGuanneixinxiList() {
        return guanneixinxiList;
    }

    public String getTongzhiyuxiaoxi() {
        return tongzhiyuxiaoxi;
    }

    public String getTongzhiyuxiaoxiIndex() {
        return tongzhiyuxiaoxiIndex;
    }

    public ArrayList<String> getTongzhiyuxiaoxiList() {
        return tongzhiyuxiaoxiList;
    }

    public String getTushuguanfengcai() {
        return tushuguanfengcai;
    }

    public String getTushuguanfengcaiIndex() {
        return tushuguanfengcaiIndex;
    }

    public ArrayList<String> getTushuguanfengcaiList() {
        return tushuguanfengcaiList;
    }

    public String getXiazaikongjian() {
        return xiazaikongjian;
    }

    public String getXiazaikongjianIndex() {
        return xiazaikongjianIndex;
    }

    public ArrayList<String> getXiazaikongjianList() {
        return xiazaikongjianList;
    }

    public String getYewujiaoliu() {
        return yewujiaoliu;
    }

    public String getYewujiaoliuIndex() {
        return yewujiaoliuIndex;
    }

    public ArrayList<String> getYewujiaoliuList() {
        return yewujiaoliuList;
    }

    public void setGuanneixinxi(String guanneixinxi) {
        this.guanneixinxi = guanneixinxi;
        guanneixinxiList.addAll(ArrayUtil.toList(StringUtil.split(guanneixinxi, ",")));
    }

    public void setGuanneixinxiIndex(String guanneixinxiIndex) {
        this.guanneixinxiIndex = guanneixinxiIndex;
    }

    public void setGuanneixinxiList(ArrayList<String> guanneixinxiList) {
        this.guanneixinxiList = guanneixinxiList;
    }

    public void setTongzhiyuxiaoxi(String tongzhiyuxiaoxi) {
        this.tongzhiyuxiaoxi = tongzhiyuxiaoxi;
        tongzhiyuxiaoxiList.addAll(ArrayUtil.toList(StringUtil.split(tongzhiyuxiaoxi, ",")));
    }

    public void setTongzhiyuxiaoxiIndex(String tongzhiyuxiaoxiIndex) {
        this.tongzhiyuxiaoxiIndex = tongzhiyuxiaoxiIndex;
    }

    public void setTongzhiyuxiaoxiList(ArrayList<String> tongzhiyuxiaoxiList) {
        this.tongzhiyuxiaoxiList = tongzhiyuxiaoxiList;
    }

    public void setTushuguanfengcai(String tushuguanfengcai) {
        this.tushuguanfengcai = tushuguanfengcai;
        tushuguanfengcaiList.addAll(ArrayUtil.toList(StringUtil.split(tushuguanfengcai, ",")));
    }

    public void setTushuguanfengcaiIndex(String tushuguanfengcaiIndex) {
        this.tushuguanfengcaiIndex = tushuguanfengcaiIndex;
    }

    public void setTushuguanfengcaiList(ArrayList<String> tushuguanfengcaiList) {
        this.tushuguanfengcaiList = tushuguanfengcaiList;
    }

    public void setXiazaikongjian(String xiazaikongjian) {
        this.xiazaikongjian = xiazaikongjian;
        xiazaikongjianList.addAll(ArrayUtil.toList(StringUtil.split(xiazaikongjian, ",")));
    }

    public void setXiazaikongjianIndex(String xiazaikongjianIndex) {
        this.xiazaikongjianIndex = xiazaikongjianIndex;
    }

    public void setXiazaikongjianList(ArrayList<String> xiazaikongjianList) {
        this.xiazaikongjianList = xiazaikongjianList;
    }

    public void setYewujiaoliu(String yewujiaoliu) {
        this.yewujiaoliu = yewujiaoliu;
        yewujiaoliuList.addAll(ArrayUtil.toList(StringUtil.split(yewujiaoliu, ",")));
    }

    public void setYewujiaoliuIndex(String yewujiaoliuIndex) {
        this.yewujiaoliuIndex = yewujiaoliuIndex;
    }

    public void setYewujiaoliuList(ArrayList<String> yewujiaoliuList) {
        this.yewujiaoliuList = yewujiaoliuList;
    }

    public String getCustomlinks() {
        return customlinks;
    }

    public void setCustomlinks(String customlinks) {
        this.customlinks = customlinks;
    }

}
